<?php
	$unitno = $_POST['unitno'];
	$streetno = $_POST['streetno'];
	$streetname = $_POST['streetname'];
	$streettype = $_POST['streettype'];
	$suburb = $_POST['suburb'];
	$postcode = $_POST['postcode'];
	
	if (checkGroupAddress($unitno, $streetno, $streetname, $streettype, $suburb, $postcode) == 0) {
		$result = addNewGroup($unitno, $streetno, $streetname, $streettype, $suburb, $postcode);
		
		if ($result == 1) {
			$groupid = checkGroupAddress($unitno, $streetno, $streetname, $streettype, $suburb, $postcode);
			
			$result = addGroupUser($groupid, $_SESSION['username'], "Y");
			
			if ($result == 1) {
				echo "<p>Your Flatshare Group has been successfully created!</p>";
				removeAllInvites($_SESSION['username']);
			}
			else {
				echo "<p>Your Flatshare Group has been successfully created, but we were unable to add you to the group for technical reasons. Please contact the administrator</p>";
			}
		}
		else {
			echo "<p>There was an error processing your request. Please try again.</p>";
			include("flatshare_php/group_create_form.php");
		}
	}
	else {
		echo "<p>The address you entered is already part of a Flatshare Group. Please contact the administrator of this group if you feel you should be a member.</p>";
	}
?>